#ifndef _SERVICE_H_
#define _SERVICE_H_

#include "Common.h"
#include <sys/poll.h>
#include <sys/epoll.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <list>
#include <string.h>
#include "MyThread.h"
class Service 
{
	public:
		virtual ~Service()	{}
		Service();
		
		virtual void Main(); 

		virtual void CallBack() = 0;
		
		virtual bool Init();
};

class NetService : public Service , public Singleton<NetService>
{
	friend class SingletonFactory<NetService>;
	public:
		virtual ~NetService()	{}

		virtual bool Init();

		virtual void CallBack();
	public:
		int epoll_handle;	//epoll handle
		int socket;
	
	protected:
		NetService();
};

class Processor : public MyThread , public Singleton<Processor>
{
	friend class SingletonFactory<Processor>;
	public:
		virtual ~Processor()	{}

		void Loop();

		void AddClient(struct sockaddr_in& addr, int socket);

		virtual bool run();
		struct ClientInfo
		{
			ClientInfo()
			{
				memset(this,0, sizeof(*this));
			}
			struct sockaddr_in addr;
			int socket;
			int socket_handle;
		};

		typedef std::list<ClientInfo>	ClientCont;
		typedef ClientCont::iterator ClientContIter;

		ClientCont clients;
	protected:
		Processor();

	public:
		int handle;	//epoll
};
#endif
